import { findAllPlan, findPlan, delPlan } from "@/apis/planApi";
import { defineStore } from "pinia";
import { ref } from "vue";

const plans = ref<PlanModel[]>([]);
const plan = ref<PlanModel>();

export default defineStore("plan", () => {
  async function all(args: Record<string, any>) {
    const { data } = await findAllPlan(args);
    plans.value = data;
  }

  async function find(id: number) {
    const { data } = await findPlan(id);
    plan.value = data;
  }

  async function del(id: number) {
    await delPlan(id);
  }

  return { plan, plans, all, find, del };
});
